/**
 * SEVAS - Swiss Electronic Vaccination Advisor Service / Agile Development
 *
 * $Id: Vaccination.java 29 2010-08-18 16:51:14Z zimmr7@bfh.ch $
 */
package ch.bfh.sevas.gui;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ColorRenderer extends DefaultTableCellRenderer {

    private static final Color RED = new Color(255, 153, 153);
    private static final Color GREEN = new Color(153, 255, 153);
    private static final Color BLACK = new Color(0, 0, 0);

    public ColorRenderer() {
        super();
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        try {
            String state = value.toString();

            setHorizontalAlignment(CENTER);

            if (state.equals("DONE")) {
                setBackground(ColorRenderer.GREEN);
                setForeground(ColorRenderer.BLACK);
            } else if (state.equals("PENDING")) {
                setBackground(ColorRenderer.RED);
                setForeground(ColorRenderer.BLACK);
            } else if (column == 0) {
                setHorizontalAlignment(LEFT);
                setBackground(table.getTableHeader().getBackground());
                setForeground(Color.BLACK);
            } else {
                setBackground(table.getBackground());
                setForeground(Color.BLACK);
            }
        } catch (Exception ignore) {}
        return this;
    }
}
